﻿using Saisie_des_prélèvements.Models;
using System;
using System.Linq;
using System.Collections.Generic;


namespace Saisie_des_prélèvements.ViewModels
{
    public class TakenAnalyzeViewModel : ViewModelBase
    {
        #region Properties

        private int analyze_id = 0;
        public int AnalyzeId
        {
            get
            { return analyze_id; }

            set
            {
                if (analyze_id == value)
                { return; }

                analyze_id = value;
                RaisePropertyChanged("AnalyzeId");
            }
        }

        private string analyze_code = string.Empty;
        public string AnalyzeCode
        {
            get
            { return analyze_code; }

            set
            {
                if (analyze_code == value)
                { return; }

                analyze_code = value;
                RaisePropertyChanged("AnalyzeCode");
            }
        }

        private string analyze_label = string.Empty;
        public string AnalyzeLabel
        {
            get
            { return analyze_label; }

            set
            {
                if (analyze_label == value)
                { return; }

                analyze_label = value;
                RaisePropertyChanged("AnalyzeLabel");
            }
        }

        private string analyze_value = string.Empty;
        public string AnalyzeValue
        {
            get
            { return analyze_value; }

            set
            {
                if (analyze_value == value)
                { return; }

                analyze_value = value;
                RaisePropertyChanged("AnalyzeValue");
            }
        }

        private int? taken_id;
        public int? TakenId
        {
            get
            { return taken_id; }

            set
            {
                if (taken_id == value)
                { return; }

                taken_id = value;
                RaisePropertyChanged("TakenId");
            }
        }

        private bool? to_do = false;
        public bool? ToDo
        {
            get
            { return to_do; }

            set
            {
                if (to_do == value)
                { return; }

                to_do = value;
                RaisePropertyChanged("ToDo");
            }
        }

        private int? user_create = 0;
        public int? UserCreate
        {
            get
            { return user_create; }

            set
            {
                if (user_create == value)
                { return; }

                user_create = value;
                RaisePropertyChanged("UserCreate");
            }
        }

        private DateTime? date_create = System.DateTime.Today;
        public DateTime? DateCreate
        {
            get
            { return date_create; }

            set
            {
                if (date_create == value)
                { return; }

                date_create = value;
                RaisePropertyChanged("DateCreate");
            }
        }

        #endregion "Properties"

        public List<TakenAnalyzeViewModel> GetAnalyzeByTakenId(int TakenId)
        {
            var db = new SQLite.SQLiteConnection(App.DBPath);
            List<TakenAnalyzeViewModel> result = db.Query<TakenAnalyzeViewModel>(
                string.Format("SELECT DISTINCT analyze_code AS AnalyzeCode, analyze_label AS AnalyzeLabel, analyze_value AS AnalyzeValue, taken_id AS TakenId FROM k_taken_analyze WHERE to_do = 1 AND taken_id='{0}'", TakenId)
                );

            return result;
        }
    }
}
